<template>
	<view>
		<uni-section title="基础信息" type="line" style="color: #409EFF;"></uni-section>
		<uni-list style="width:95%">
			<uni-list-item :title="'所属团队： ' + team.name" :rightText="team.note" thumbSize="lg" :thumb="team.avatarUrl"/>
			<uni-list-item :title="'所属项目： ' + project.name" :rightText="project.note" thumbSize="lg" :thumb="project.avatarUrl"/>
			<uni-list-item :title="'员工:' + employee.realName == null || employee.realName == '' ? employee.nickName : employee.realName" 
			:rightText="employee.phone" thumbSize="lg" :thumb="employee.avatar == '' ? defaultAvatar : employee.avatar"/>
		</uni-list>		
		<uni-section title="工作记录" type="line"></uni-section>
		<uni-collapse ref="collapse" style="margin-left: 20rpx;font-size: 28rpx; ">
			<uni-collapse-item open="true" :title="'加班 ' + salary.extWorkHours + ' 小时'" style="margin-left: 20rpx;" >
				<uni-list style="width:95%">
					<uni-list-chat v-for="(item, index) in workLists"
					:key="index"
					:title="item.workList.name"
					:note="item.workList.workStatus == 'EXTWORK' ? item.workList.extWorkStart + '至'+ item.workList.extWorkEnd : '地点：' + item.workList.errandPlace"
					:avatar="item.imageList.length > 0 ? item.imageList[0].url : noImage"
					:time="item.workList.workDate" 
					:badgeText="item.workList.workStatus == 'NORMAL' ? '正常' : item.workList.workStatus == 'EXTWORK' ? '  加班 ' + item.workList.extWorkHours + '小时' : '出差：'"
					/>
				</uni-list>
			</uni-collapse-item>
		</uni-collapse>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				salary: {},
				workLists: [],
				team: {},
				project: {},
				employee: {},
				noImage: '/static/noImage.png',
				defaultAvatar: '/static/defaultAvatar.png',
			}
		},
		onLoad() {
			this.salary = this.$dry.get("salary");
			uni.removeStorageSync("salary");
			this.getWorkList();
			this.getTeamById();
			this.getProjectById();
			this.getEmployeeById();
		},
		onShow() {
			
		},
		onShareAppMessage(res) {
		    if (res.from === 'button') {// 来自页面内分享按钮
		      console.log(res.target)
		    }
		    return {
		      title: '大家都在用这款小工具管理项目，快来试试吧！！！',
		      path: '/pages/index/index'
		    }
		},
		methods: {
			getWorkList() {
				var token = this.$dry.getToken();
				if(token){
					var data = this.$request.run("getWorkListByProjectAndEmployee", token);
				    uni.request({
				    	url: data.url,
				    	method: data.method,
				    	header: data.header,
				    	data: {
							"projectId": this.salary.projectId,
							"employeeId": this.salary.employeeId,
						},
						success: data => {
							if(data.statusCode === 200) {
								this.workLists = data.data;
							}
						}
					})
				}
			},
			getProjectById() {
				var token = this.$dry.getToken();
				if(token){
					var data = this.$request.run("getProjectById", token);
				    uni.request({
				    	url: data.url,
				    	method: data.method,
				    	header: data.header,
				    	data: {
							"projectId": this.salary.projectId,
						},
						success: data => {
							if(data.statusCode === 200) {
								this.project = data.data;
							}
						}
					})
				}
			},
			getTeamById() {
				var token = this.$dry.getToken();
				if(token) {
					var data = this.$request.run("getTeamById", token);
					 uni.request({
					 	url: data.url,
						method: data.method,
						header: data.header,
						data: {
							"id": this.salary.teamId,
						},
						success: data => {
							if(data.statusCode === 200) {
								this.team = data.data;
							}
						}
					 })
				}
			},
			getEmployeeById() {
				var token = this.$dry.getToken();
				if(token) {
					var data = this.$request.run("getEmployeeById", token);
					 uni.request({
					 	url: data.url,
						method: data.method,
						header: data.header,
						data: {
							"id": this.salary.employeeId,
						},
						success: data => {
							if(data.statusCode === 200) {
								this.employee = data.data;
							}
						}
					 })
				}
			},
			getNumberOfDays(date1,date2){//获得天数
			    //date1：开始日期，date2结束日期
			    var a1 = Date.parse(new Date(date1));
			    var a2 = Date.parse(new Date(date2));
			    var day = parseInt((a2-a1)/ (1000 * 60 * 60 * 24));//核心：时间戳相减，然后除以天数
			    return day
			},
			getNumberOfHours(date1,date2){//获得小时数
			    //date1：开始日期，date2结束日期
			    var a1 = Date.parse(new Date(date1));
			    var a2 = Date.parse(new Date(date2));
			    var hour = parseInt((a2-a1)/ (1000 * 60 * 60));//核心：时间戳相减，然后除以小时数
			    return hour
			}
		}
	}
</script>

<style scoped>
	
	.content {
		padding-left: 30rpx;
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: left;
		justify-content: center;
	}
	.content-box-text {
		font-size: 24rpx;
		line-height: 44rpx;
	}
	.tag-box {
		display: flexbox;
		margin-left: 20rpx;
	}
	.grid-item-box {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 30rpx 0;
	}
	.image {
		width: 200rpx;
		height: 150rpx;
	}
	#img-box {
		width: 90%;
		margin: 0 auto;
		margin-bottom: 50rpx;
	}
</style>
